import typing


# 题目：请实现一个函数，输入一个整数，输出该数二进制表示中1的个数

# def number_of_1(num):
#     count = 0
#     flag = 1
#     while flag:
#         print(flag)
#         if num & flag:
#             count += 1
#         flag = flag << 1
#     return count


def number_of_1(num: int):
    count = 0
    while num:
        count += 1
        num = (num-1)&num
    return count

if __name__ == '__main__':
    print(number_of_1(9))
    print(number_of_1(10))
    print(number_of_1(11))